package mylab.starters.mybatis.interceptor.impl.dynamicTable.impl;

import cn.hutool.core.text.CharSequenceUtil;
import mylab.starters.mybatis.interceptor.impl.dynamicTable.AutoCreatedTableNameHandler;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 按年分表解析:[TABLE_yyyy]
 */
public class YearsTableNameHandler extends AutoCreatedTableNameHandler {

    @Override
    protected String getDynamicTableName(String sql, String tableName) {
        String dateString = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy"));
        return CharSequenceUtil.format("{}_{}", tableName, dateString);
    }
}
